package logic

import (
	"box-fresh/model/mysql"
	"context"
	"errors"

	"box-fresh/hemarpc/hemarpc"
	"box-fresh/hemarpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HeShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHeShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HeShowLogic {
	return &HeShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HeShowLogic) HeShow(in *hemarpc.HeShowRequest) (*hemarpc.HeShowResponse, error) {
	// todo: add your logic here and delete this line
	var hes mysql.Hes
	if err := hes.HesShow(mysql.DB, in.HesId); err != nil {
		return nil, errors.New("商品不存在")
	}
	return &hemarpc.HeShowResponse{
		HesId:  int64(hes.ID),
		Name:   hes.Name,
		Weight: float32(hes.Weight),
		Price:  float32(hes.Price),
	}, nil
}
